﻿<cfsilent>
	<cfscript>
		
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");

		termId = event.getArg("TermID", event.getArg("TID"));
		depId = event.getArg("DepID");
		
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");
		
		event.setArg("pageTitle", "教学任务安排 - 教学任务 - 选课学生名单");
		
		currentTab = event.getArg("TabID", "labStudent");
		
		passArgs = structNew();
		structInsert(passArgs, "TID", termId, true);
		structInsert(passArgs, "DepID", depId, true);
		
		targetArgs = structNew();
		structInsert(targetArgs, "TID", termId, true);
		structInsert(targetArgs, "TSK", taskId, true);
		structInsert(targetArgs, "TT", taskType, true);
		
		rs_course = queryNew("course_name");
		
		/* 课程相关信息 */
		switch (taskType) {
			
			case "C":
				sql = "	SELECT
							c.course_name,c.course_credit,c.period,c.period_theory,
							i.institute_name,
							cc.cat_name,
							CASE WHEN c.intro IS NULL THEN '-' ELSE c.intro END intro,
							CASE WHEN c.reference_books IS NULL THEN '-' ELSE c.reference_books END reference_books,
							CASE WHEN c.course_english IS NULL THEN '-' ELSE c.course_english END course_english,
							c.cid,
							c.course_code
						FROM
							t_common_task t INNER JOIN t_course c ON c.cid = t.cid INNER JOIN t_institute i ON i.institute_id = c.institute_id
							INNER JOIN t_course_catalog cc ON cc.cat_id = c.cat_id
						WHERE
							t.tsk_id = :taskId ";
				break;

			case "P":
				sql = "	SELECT
							c.course_name,c.course_credit,c.period,c.period_theory,
							i.institute_name,
							cc.cat_name,
							CASE WHEN c.intro IS NULL THEN '-' ELSE c.intro END intro,
							CASE WHEN c.reference_books IS NULL THEN '-' ELSE c.reference_books END reference_books,
							CASE WHEN c.course_english IS NULL THEN '-' ELSE c.course_english END course_english,
							c.cid,
							c.course_code
						FROM
							t_task t INNER JOIN t_course c ON c.cid = t.cid INNER JOIN t_institute i ON i.institute_id = c.institute_id
							INNER JOIN t_course_catalog cc ON cc.cat_id = c.cat_id
						WHERE
							t.tsk_id = :taskId ";
				break;
			
			case "T":
				sql = "	SELECT
							c.course_name,c.course_credit,c.period,c.period_theory,
							i.institute_name,
							cc.cat_name,
							CASE WHEN c.intro IS NULL THEN '-' ELSE c.intro END intro,
							CASE WHEN c.reference_books IS NULL THEN '-' ELSE c.reference_books END reference_books,
							CASE WHEN c.course_english IS NULL THEN '-' ELSE c.course_english END course_english,
							c.cid,
							c.course_code
						FROM
							t_sport_task t INNER JOIN t_course c ON c.cid = t.cid INNER JOIN t_institute i ON i.institute_id = c.institute_id
							INNER JOIN t_course_catalog cc ON cc.cat_id = c.cat_id
						WHERE
							t.tsk_id = :taskId ";
				break;
			
			case "R":
				sql = "	SELECT
							c.course_name,c.course_credit,c.period,c.period_theory,
							i.institute_name,
							cc.cat_name,
							CASE WHEN c.intro IS NULL THEN '-' ELSE c.intro END intro,
							CASE WHEN c.reference_books IS NULL THEN '-' ELSE c.reference_books END reference_books,
							CASE WHEN c.course_english IS NULL THEN '-' ELSE c.course_english END course_english,
							c.cid,
							c.course_code
						FROM
							t_reopen_task t INNER JOIN t_course c ON c.cid = t.cid INNER JOIN t_institute i ON i.institute_id = c.institute_id
							INNER JOIN t_course_catalog cc ON cc.cat_id = c.cat_id
						WHERE
							t.tsk_id = :taskId ";
				break;
			
		}
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "taskId", value = taskId, cfsqltype = "cf_sql_varchar");
		rs_course = queryObj.execute(sql = sql).getResult();
		
		
		/* 选课数据 */
		
		sql = "	SELECT
					stu.stu_id,stu.stu_name,clz.cls_name,clz.grade,
					i.institute_short,
					sc.st,sc.choose_time,sc.retaking,sc.choose_prop,sc.retaking,
					sc.scc_id,c.cid,sc.task_type,sc.task_id
				FROM
					t_student_course sc INNER JOIN t_student stu ON stu.stu_id = sc.stu_id
					INNER JOIN t_class clz ON clz.cls_id = stu.cls_id INNER JOIN t_subject sbj ON sbj.sbj_id = clz.sbj_id
					INNER JOIN t_institute i ON i.institute_id = sbj.institute_id INNER JOIN t_course c ON c.cid = sc.cid
				WHERE
					sc.task_id = :taskId 
				ORDER BY
					stu.stu_id";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "taskId", value = taskId, cfsqltype = "cf_sql_varchar");
		rs_chooser = queryObj.execute(sql = sql).getResult();
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('taskClass', passArgs)#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">教学任务调整</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i><cfoutput>#rs_course.course_name#</cfoutput> - <cfoutput>#rs_course.cat_name#</cfoutput>
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
			
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labCourse">class="active"</cfif> id="labCourse" tabTarget="Course">课程介绍</span>
						<span <cfif currentTab eq "labStudent">class="active"</cfif> id="labStudent" tabTarget="Student">选课学生名单</span>
					</div>
				</div>
				
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Course" class="tabContent">
					
					<div class="noticeBlock">
						<h3>《<cfoutput>#rs_course.course_name#</cfoutput>》 任课单位: <cfoutput>#rs_course.institute_name#</cfoutput></h3>
						<p>
							<span class="img icon16x16 message"></span>
							<cfif rs_course.course_code neq "-">课程号 <em><cfoutput>#rs_course.course_code#</cfoutput></em></cfif>
							总学时 <em><cfoutput>#rs_course.period#</cfoutput></em>, 其中理论学时 <em><cfoutput>#rs_course.period_theory#</cfoutput></em>. 课程总学分:<em><cfoutput>#numberFormat(rs_course.course_credit, '_.00')#</cfoutput></em>
							英文课程名 <em><cfif rs_course.course_english eq "-">None<cfelse><cfoutput>#rs_course.course_english#</cfoutput></cfif></em>
						</p>
					</div>
					
					<div id="courseInfo">

						<div class="noticeBlock">
							<h2>课程简介</h2>
							
							<cfif rs_course.intro neq "-">
								<cfoutput>#stringAdvice.XHTMLParagraphFormat(rs_course.intro)#</cfoutput>
								<cfelse>
								暂无
							</cfif>
						</div>
					
						<div class="noticeBlock">
							<h2>参考书籍</h2>
							
							<cfif rs_course.reference_books neq "-">
								<cfoutput>#stringAdvice.XHTMLParagraphFormat(rs_course.reference_books)#</cfoutput>
								<cfelse>
								暂无
							</cfif>
						</div>
					</div>
					
				</div>
				
				<div id="Student" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
							<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('applyWizardByCourse', targetArgs)#</cfoutput>"><i class="mrs img btnAddWhite"></i><span class="uiButtonText">添加选课学生</span></a>
							<cfif rs_chooser.recordCount>
								<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('chooserPrint', targetArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">打印选课名单</span></a>
								<a class="uiButton" href="<cfoutput>#buildURL('chooserDownloadExcel', targetArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载电子表格</span></a>
							</cfif>
						</div>
						<h3>《<cfoutput>#rs_course.course_name#</cfoutput>》 任课单位: <cfoutput>#rs_course.institute_name#</cfoutput></h3>
						<p>
							<span class="img icon16x16 message"></span>
							<cfif rs_course.course_code neq "-">课程号 <em><cfoutput>#rs_course.course_code#</cfoutput></em></cfif>
							总学时 <em><cfoutput>#rs_course.period#</cfoutput></em>, 其中理论学时 <em><cfoutput>#rs_course.period_theory#</cfoutput></em>. 课程总学分:<em><cfoutput>#numberFormat(rs_course.course_credit, '_.00')#</cfoutput></em>
						</p>
					</div>
					
					<div id="taskChooser">
						<!--- 显示选课记录--->
						<!-- taskChooser -->
						<cfoutput>#event.getArg("taskChooser")#</cfoutput>
						<!-- /taskChooser -->
					</div>

				</div>
				
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					function removeTask(chooserId, courseId, stuId, termId, taskType, taskId) {
							
						/* 显示阻挡信息 */
						$.blockUI({ 
									message: '正在删除课程...',
									css: { 
											'width': '16%',
											'left': '42%',
											'border': 'none', 
											'padding': '15px 5px', 
											'backgroundColor': '#090', 
											'border-radius': '4px', 
											'opacity': .8, 
											'color': '#fff',
											'cursor': null
											},
									overlayCSS: {
											'backgroundColor': '#000', 
											'opacity': .1 ,
											'cursor': null
											}
									}); 
						
						/* 异步提交退课数据 */
						$.post(
								"<cfoutput>#buildURL('apiRemoveTask')#</cfoutput>", 
								{
									'STU': stuId,
									'TID': termId,
									'CID' : courseId,
									'TSK': taskId,
									'TT' : taskType,
									'SCC' : chooserId,
									'seed': (new Date()).getTime()
								},
								function(data) {
										
									//$("#out").html(data);
									result = $.parseJSON(data);
										
									if ( result.success ) {

										/* 更新学生选课记录 */
										$.post(
												"<cfoutput>#buildURL('apiTaskChoosen')#</cfoutput>", 
												{
													'TID': '<cfoutput>#termId#</cfoutput>',
													'TSK': '<cfoutput>#taskId#</cfoutput>',
													'TT': '<cfoutput>#taskType#</cfoutput>',
													'seed': (new Date()).getTime()
												},
												function(tableData) {
												
													$("#taskChooser").html(tableData);
														
													/* 取消阻挡 */
													$.unblockUI();
														
												});
									}
									else {
										alert(result.reason);
										/* 取消阻挡 */
										$.unblockUI();
									}
										
								});
							
					}
					// -->
					//]]>
				</script>
				
			</div>
		</li>
	</ul>
</div>





